package com.threadDemo;


import java.util.Scanner;

public class AccountOperator implements Runnable{

    private Account account;

    public AccountOperator(Account account){
        this.account = account;
    }

    @Override
    public void run() {

        synchronized(account){

           business();
//            account.deposit(5000);
//            account.withdraw(500);
//            System.out.println(Thread.currentThread().getName()+":"+account.getbalance());

        }
    }


    public void business(){

        if("A".equals(account.getBus())){
            account.deposit(account.getAmount());
            System.out.println(Thread.currentThread().getName()+":"+account.getbalance());
        }else if("B".equals(account.getBus())){
            account.withdraw(account.getAmount());
            System.out.println(Thread.currentThread().getName()+":"+account.getbalance());
        }else {
            System.out.println("请重新选择业务！");
        }

    }






    public static void main(String[] args) {


        System.out.println("选择你要办理的业务，A（取），B（存）");
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
       // System.out.println(str);
        System.out.println("金额数");
        String amt = sc.next();
        Account account = new Account("zhansan",Float.parseFloat(amt),str);
        AccountOperator accountOperator = new AccountOperator(account);
     //   final int THREAD_NUM =5;
        Thread thread = new Thread(accountOperator,"Thread");
        thread.start();
     //   Thread[] threads = new Thread[THREAD_NUM];
    //    for(int i =0;i<THREAD_NUM;i++){

        //    threads[i] = new Thread(accountOperator,"Thread"+i);
        //    threads[i].start();
   //     }




    }

}
